var log=require('logging');
var object=require('./object');

exports.typeOf=function(value) {
    var s = typeof value;
    if (s === 'object') {
        if (value) {
            if (value instanceof Array) {
                s = 'array';
            }
        } else {
            s = 'null';
        }
    }
    return s;
}

exports.lookup=function(doc, path)
{
  var docPath=object.cloneArray(path);

  while(docPath.length>0)
  {
    var key=docPath.shift();
    doc=doc[key];
  }

  return doc;
}

exports.set=function(doc, path, value)
{
  var key;
  var docPath=object.cloneArray(path);

  while(docPath.length>1)
  {
    key=docPath.shift();
    doc=doc[key];
  }

  key=docPath.shift();

  doc[key]=value;
}

exports.map=function(l, f)
{
  var ps=[];
  var x;
  var results=[];

  for(x=0; x<l.length; x++)
  {
    results.push(f(l[x]));
  }

  return results;
};
